<style>
  .store-area-list li{margin-bottom: 10px;}
</style>
<form method="post" action="<{link app=mobileapi ctl=admin_info act=suggest_type}>" class="tableform" id="tip_edit">
  <table>
    <tbody>
      <tr>
        <td>
          <ul class="store-area-list" id="tip_area">
              <li class="title"><{t}>意见反馈类型<{/t}></li>
            <{foreach from=$suggest_type item=item key=key name=name}>
            <li class="item">
              <{input type="text" vtype="required" name="values[{$key}]" maxlength="100" value=$item size="60" pattern="((?!#\!\!#).)*" }>
              <{if $smarty.foreach.name.iteration>1}>
              <a href="javascript:void(0);" class="del">删除</a>
              <{/if}>

            </li>
            <{/foreach}>
          </ul>
          <div><{button app=b2c class="btn" label="添加反馈类型" icon="add_icon.gif" id="add_tip"}></div>
        </td>
        <td>
          <h5>说明：</h5>
          <p>
            建议类型文字在6字以内
          </p>
        </td>
      </tr>
      <tr>
        <td colspan="2"><{button class="btn btn-primary" type="submit" label="保存"}></td>
      </tr>
    </tbody>
  </table>
</form>
<script type="text/javascript">
(function(){
    $('tip_edit').getElements('.del').addEvent('click', function(){
      this.getParent('.item').destroy();
    });

  var id = 1;
  function tpl(id) {
      var tpl = '';
      tpl+='<{input type="text" vtype="required" name="values[new_' + id + ']" id="" maxlength="100" size="60" pattern="((?!#\!\!#).)*" }> <a href="javascript:void(0);" class="del">删除</a>';
      return tpl;
  }
  $('add_tip').addEvent('click', function(){
      var el = new Element('li.item', {html: tpl(id++)}).inject($('tip_area'));
      el.getElement('.del').addEvent('click', function(){
          this.getParent('.item').destroy();
      });
  });

  $('tip_edit').store('target', {
    onComplete: function(rs){
        rs = JSON.decode(rs);
        if(rs.success)
        $('tip_edit').getParent('.dialog').retrieve('instance').close();
    }
  });

})()
</script>
